package fts.ftsui.observers;

import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;

import fts.ftsmonitoring.InitializationStatus;
import fts.ftsmonitoring.initializer.IInitializerObserver;


public class InitializerObserver implements IInitializerObserver
{
	Label label;
	ProgressBar progressBar;
	public InitializerObserver(Label statusLabel, ProgressBar progress)
	{
		this.label = statusLabel;
		this.progressBar = progress;
	}
	
	public void onInitializerProgressChange(final int progress)
	{
		if(progressBar.isDisposed())
			return;
		if(progressBar.getDisplay().isDisposed())
			return;
		progressBar.getDisplay().asyncExec(new Runnable()
		{
			
			public void run()
			{
				if(progressBar.isDisposed())
					return;
				progressBar.setSelection(progress);
			}
		});
	}

	public void onInitializerStatusChange(final InitializationStatus status)
	{
		if(label.isDisposed())
			return;
		if(label.getDisplay().isDisposed())
			return;
		label.getDisplay().asyncExec(new Runnable()
		{
			
			public void run()
			{
				if(label.isDisposed())
					return;

				label.setText(status.toString());
			}
		});
	}

}
